#include "OperateLimitPart.h"
#include "Player.h"
#include "PlayerMgr.h"
#include "Common/Utility/TimeUtility.h"
#include "Common/Event/Event.h"
#include "Common/MissionDefine.h"
#include "Common/TableDataEx/OperateCfg.h"
#include "ServerModule/LogicActivityModule.h"
#include "Common/TableData/AreaAreaCfg.h"
#include "Common/TableData/NpcNpcCfg.h"
#include "Character/AdventurePart.h"

using namespace ProtoBuf;

OperateLimit::OperateLimit()
{
	mLimitCount = 0;
	mUpdateType = 0;
	mLastTime = 0;
	mSendClient = false;
}

OperateLimit::~OperateLimit()
{
}

void OperateLimit::SetType(uint32_t updateType, bool sendClient)
{
	mUpdateType = updateType;
	mSendClient = sendClient;
}

void OperateLimit::Attach(const CharacterDBSingleOperateLimitInfo& singleOperateLimitInfo)
{
	mLimitCount = singleOperateLimitInfo.value();
	mLastTime = singleOperateLimitInfo.lasttime();
	uint32_t nNowTime = Time::Now().UnixSec();
	if (IsNeedUpdate(nNowTime))
	{
		mLimitCount = 0;
		mLastTime = nNowTime;
	}
}

bool OperateLimit::AddLimitCount(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t val)
{
	uint32_t nNowTime = Time::Now().UnixSec();

	/*if (IsNeedUpdate(nNowTime)){
		SetLimitCount(val);
	}
	else {
		SetLimitCount(mLimitCount + val);
	}*/

	SetLimitCount(mLimitCount + val);

	mLastTime = nNowTime;

	return true;
}

bool OperateLimit::IsNeedUpdate(uint32_t now)
{
	bool ret = false;
	switch (mUpdateType){
	case PRSUTE_DAY_UPDATE:
	{
		if (now > mLastTime){
			ret = TimeUtility::CheckDayUpdate(now, mLastTime);
		}
	}
	break;
	case PRSUTE_WEEK_UPDATE:
	{
		if (now > mLastTime){
			ret = TimeUtility::CheckWeekUpdate(now, mLastTime);
		}
	}
	break;
	default:
		break;
	}

	return ret;
}

void OperateLimit::SetLimitCount(uint32_t val)
{
	mLimitCount = val;
}

uint32_t OperateLimit::GetLimitCount(PLAYER_ROLE_STATIS_TYPE_E type)
{
	//uint32_t nNowTime = Time::Now().UnixSec();
	//if (IsNeedUpdate(nNowTime))
	//{
	//	mLastTime = nNowTime;
	//	mLimitCount = 0;
	//}

	return mLimitCount;
}

OperateLimitPart::OperateLimitPart()
{
	m_mOperateLimit.clear();
	m_statisticData.clear();
}

OperateLimitPart::~OperateLimitPart()
{

}

bool OperateLimitPart::Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB)
{
	Part::Init(pMaster, partType);

	//初始化所有统计值
	m_mOperateLimit.resize(PRSTE_MAX);

	//这里注册类
	//m_mOperateLimit[PRSTE_TEST].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_PESTILENCE].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_TOWER].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_GUARD].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_CLOUD].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_HUOYUEDU_REWARD].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_HUOYUEDU].SetType(PRSUTE_DAY_UPDATE);
	m_mOperateLimit[PRSTE_RUNBUSSION_STAGE].SetType(PRSUTE_NOT_UPDATE, true);


	//注册完后初始化数据
	const CharacterDBOperateLimitInfo& operateLimitInfo = pCharacterDB->operatelimitdata();
	for (int32_t i = 0; i < operateLimitInfo.operatelimitinfo_size(); i++)
	{
		const CharacterDBSingleOperateLimitInfo& singleOperateLimitInfo = operateLimitInfo.operatelimitinfo(i);

		uint32_t limitType = singleOperateLimitInfo.type();
		if (limitType >= PRSTE_MAX)
		{
			MMOLOG_FMT_ERROR("[logic] OperateLimitPart::Attach but limitType >= PRSTE_MAX...limitType=%d", limitType);
			continue;
		}

		m_mOperateLimit[limitType].Attach(singleOperateLimitInfo);
	}

	if (operateLimitInfo.has_operate_data())
	{
		const CharacterDBOperateInfo &proto = operateLimitInfo.operate_data();
		InitStatisticData(proto);
	}


	//订阅统计事件
	g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, m_pMaster->GetCid(), CREATURE_MONSTER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_CREATURE_DEAD, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_PASS_DUPLICATE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_DEPUTY_COLLECT_OPERATE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_DEPUTY_FORGE_EQUIP, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_DEPUTY_MAKE_OPERATE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_EQUIP_REFINE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_PAY, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_TREASURE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_ENTER_SCENE, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_ARENA_RESULT, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_EQUIP_IDENTIFY, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_ATTEND_ACTIVITY, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_FINISH_ACTIVITY, m_pMaster->GetCid(), CREATURE_PLAYER, "OperateLimitPart");
	g_GetEvent()->Subscribe(this, EVENT_CHAT, m_pMaster->GetCid(), CREATURE_PLAYER, "AdventurePart");
	g_GetEvent()->Subscribe(this, EVENT_KILL_ENEMY, m_pMaster->GetCid(), CREATURE_PLAYER, "AdventurePart");
	
	return true;
}

bool OperateLimitPart::UnInit()
{
	m_mOperateLimit.clear();
	m_statisticData.clear();
	g_GetEvent()->UnSubscribeAll(this);

	return true;
}

bool OperateLimitPart::SaveDB(CharacterDBInfo& characterDB)
{
	CharacterDBOperateLimitInfo* pOperateLimitInfo = characterDB.mutable_operatelimitdata();
	if (nullptr == pOperateLimitInfo)
	{
		LogErrFmtPrint("OperateLimitPart::SaveDB...nullptr == pOperateLimitInfo....cid:%lu ", m_pMaster->GetCid());
		return false;
	}
	for (uint32_t i = 0; i < m_mOperateLimit.size(); i++)
	{
		uint32_t limitCount = m_mOperateLimit[i].GetLimitCount();
		uint32_t lastTime = m_mOperateLimit[i].GetLastTime();
		CharacterDBSingleOperateLimitInfo* pSingleOperateLimit = pOperateLimitInfo->add_operatelimitinfo();
		if (nullptr != pSingleOperateLimit)
		{
			pSingleOperateLimit->set_type(i);
			pSingleOperateLimit->set_value(limitCount);
			pSingleOperateLimit->set_lasttime(lastTime);
		}		
	}
	CharacterDBOperateInfo *protoOperate = pOperateLimitInfo->mutable_operate_data();
	if (nullptr != protoOperate)
	{
		SetStatisticData(*protoOperate);
	}

	return true;
}


bool OperateLimitPart::OnMsgHandle(uint32_t cmd, const char* data, uint32_t len)
{
	switch (cmd)
	{
	case CLIENT_TO_LOGIC_OPERATELIMIT_GETSTAGE:
	{
		GetOperateLimitStageList(data, len);
		break;
	}
	case CLIENT_TO_LOGIC_OPERATELIMIT_SETSTAGE:
	{
		SetOperateLimitStag(data, len);
		break;
	}
	case CLIENT_TO_LOGIC_OPERATELIMIT_ACTION:
	{
		OnHandleClientAction(data,len);
		break;
	}
	default:
		break;
	}

	return true;
}

void OperateLimitPart::OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	switch (nEventID)
	{
	case EVENT_CREATURE_DEAD:
		{
			DieEvent dieEvent = *(DieEvent*)pContext;
			if (dieEvent.monsterId > 0)
			{
				OnMonsDieEvent(dieEvent);
			}
			else
			{
				OnPlayerDieEvent(dieEvent);
			}
		}
		break;
	case EVENT_PASS_DUPLICATE:
		{
			PassDupEvent passEvent = *(PassDupEvent*)pContext;
			OnPassEvent(passEvent);
		}
		break;
	case EVENT_DEPUTY_COLLECT_OPERATE:
		{
			CollectOperateEvent collSucessEvent = *(CollectOperateEvent*)pContext;
			OnCollectEvent(collSucessEvent);
		}
		break;
	case EVENT_DEPUTY_FORGE_EQUIP:
		{
			ForgeEquipEvent forgeEvent = *(ForgeEquipEvent*)pContext;
			OnMakeEvent(forgeEvent);
		}
		break;
	case EVENT_DEPUTY_MAKE_OPERATE:
		{
			MakeOperateEvent operateEvent = *(MakeOperateEvent*)pContext;
			OnMakeItemEvent(operateEvent);
		}
		break;
	case EVENT_EQUIP_REFINE:
		{
			EquipRefineEvent refineEvent = *(EquipRefineEvent*)pContext;
			OnRefineEvent(refineEvent);
		}
		break;
	case EVENT_PAY:
		{
			PayEvent payEvent = *(PayEvent*)pContext;
			OnChargeEvent(payEvent);
		}
		break;
	case EVENT_TREASURE:
		{
			TreasureEvent treasureEvent = *(TreasureEvent*)pContext;
			OnTreasureEvent(treasureEvent);
		}
		break;
	case EVENT_ENTER_SCENE:
		{
			EnterSceneEvent enterEvent = *(EnterSceneEvent*)pContext;
			OnEnterSceneEvent(enterEvent);
		}
		break;
	case EVENT_ARENA_RESULT:
		{
			ArenaResultEvent resEvent = *(ArenaResultEvent*)pContext;
			OnArenaResultEvent(resEvent);
		}
		break;
	case EVENT_EQUIP_IDENTIFY:
		{
			EquipIdentifyEvent identifyEvent = *(EquipIdentifyEvent*)pContext;
			OnIdentifyEvent(identifyEvent);
		}
		break;
	case EVENT_ATTEND_ACTIVITY:
		{
			AttendActEvent attendEvent = *(AttendActEvent*)pContext;
			OnAttendActEvent(attendEvent);
		}
		break;
	case EVENT_FINISH_ACTIVITY:
		{
			FinishActEvent finishEvent = *(FinishActEvent*)pContext;
			OnFinishActEvent(finishEvent);
		}
		break;
	case EVENT_CHAT:
		{
			ChatWorldEvent chatEvent = *(ChatWorldEvent*)pContext;
			OnWorldChatEvent(chatEvent);
		}
		break;
	case EVENT_KILL_ENEMY:
		{
			OnKillEnemyEvent();
		}
		break;
	default:
		break;
	}
}

void OperateLimitPart::GetOperateLimitStageList(const char* data, uint32_t len)
{
	ProtoBuf::CGOperateLimitStageInfoReq req;

	if (!req.ParseFromArray(data, len))
	{
		MMOLOG_FMT_ERROR("[logic] CGOperateLimitStageInfoReq parse failed...");
		return;
	}

	ProtoBuf::CGOperateLimitStageInfoRsp rsp;

	for (uint32_t i = 0; i < m_mOperateLimit.size(); i++)
	{
		if (m_mOperateLimit[i].GetSendClient())
		{
			OperateLimitStageInfo* pStageInfo = rsp.add_stageinfo();
			pStageInfo->set_type(i);
			pStageInfo->set_stage(m_mOperateLimit[i].GetLimitCount());
		}
	}

	m_pMaster->SendDataToClientEx(EMODULE_ID_OPERATELIMIT, LOGIC_TO_CLIENT_OPERATELIMIT_GETSTAGE, &rsp);
}




void OperateLimitPart::OnHandleClientAction(const char* data, uint32_t len)
{
	CGOperateLimitActionReq req;
	if (!req.ParseFromArray(data,len))
	{
		LogErrFmtPrint("OperateLimitPart::OnHandleClientAction...CGOperateLimitActionReq parse failed..");
		return;
	}
	int32_t actionType = req.action_type();
	uint32_t actionVal = req.action_val();
	AdventurePart *pAdventurePart = dynamic_cast<AdventurePart*>(m_pMaster->GetPart(PART_ADVENTURE));
	if (nullptr != pAdventurePart)
	{
		pAdventurePart->OnClientAction(actionType, actionVal);
	}

}


void OperateLimitPart::SetOperateLimitStag(const char* data, uint32_t len)
{
	ProtoBuf::CGSetOperateLimitStageReq req;

	if (!req.ParseFromArray(data, len))
	{
		MMOLOG_FMT_ERROR("[logic] CGSetOperateLimitStageReq parse failed...");
		return;
	}

	uint32_t type = req.type();
	if (type <= PRSTE_TEST || type >= PRSTE_MAX)
	{
		return;
	}

	if (!m_mOperateLimit[type].GetSendClient())
	{
		return;
	}

	m_mOperateLimit[type].SetLimitCount(req.val());
}

void OperateLimitPart::InitStatisticData(const CharacterDBOperateInfo &protoA)
{
	int32_t i = 0;
	const CharacterDBOperateMutProto &protoKillMons = protoA.kill_mons();
	int32_t isize = protoKillMons.operate_lst_size();
	for (; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoKillMons.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_MONS, proto.id(), proto.num());
	}

	const CharacterDBOperateMutProto &protoLastKillMons = protoA.last_kill_mons();
	isize = protoLastKillMons.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoKillMons.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_LAST_ATTACK, proto.id(), proto.num());
	}

	const CharacterDBOperateMutProto &protoAttendAct = protoA.attend_act();
	isize = protoAttendAct.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoAttendAct.operate_lst(i);
		//参加活动的单独处理
		m_statisticData.mapAttendActNum[proto.id()] = proto.num();
	}
	const CharacterDBOperateMutProto &protoLastAttend = protoA.last_attend_act();
	isize = protoLastAttend.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoLastAttend.operate_lst(i);
		//最后一次参加活动时间 单独处理
		m_statisticData.mapLastAttendAct[proto.id()] = proto.num();
	}
	const CharacterDBOperateMutProto &protoFinishAct = protoA.finish_act();
	isize = protoFinishAct.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoFinishAct.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_FINISH_ACT, proto.id(), proto.num());
	}
	const CharacterDBOperateMutProto &protoPassDup = protoA.pass_dup();
	isize = protoPassDup.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoPassDup.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_PASS_DUP, proto.id(), proto.num());
	}
	/*const CharacterDBOperateMutProto &protoCollAction = protoA.coll_action();
	isize = protoCollAction.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoCollAction.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT, proto.id(), proto.num());
	}
	const CharacterDBOperateMutProto &protoMakeAction = protoA.make_action();
	isize = protoMakeAction.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoMakeAction.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE, proto.id(), proto.num());
	}*/
	const CharacterDBOperateMutProto &protoCollect = protoA.collect();
	isize = protoCollect.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoCollect.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_COLLECT, proto.id(), proto.num());
	}
	const CharacterDBOperateMutProto &protoMake = protoA.make();
	isize = protoMake.operate_lst_size();
	for (i = 0; i < isize; ++i)
	{
		const CharacterDBOperateProto &proto = protoMake.operate_lst(i);
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE, proto.id(), proto.num());
	}
	m_statisticData.nMakeGoldEquipNum = protoA.make_gold_quip();
	m_statisticData.nIdentifyNum = protoA.identify();
	m_statisticData.nArenaSuccessNum = protoA.arena_success();
	m_statisticData.nDieNum = protoA.die();
	m_statisticData.nKillEnemyNum = protoA.kill_enemy();
	m_statisticData.nKillOtherCampNum = protoA.kill_enemy_camp();
	m_statisticData.nChargeNum = protoA.charge();
	m_statisticData.nGoldNum = protoA.gold();
	m_statisticData.nTreasureNum = protoA.treasure();
	m_statisticData.nPandosTransNum = protoA.pandos_trans();
	m_statisticData.nWorldChatNum = protoA.world_chat();
	m_statisticData.nRefineSuccessNum = protoA.refine_success();
	m_statisticData.nRefineFailNum = protoA.refine_fail();
}

void OperateLimitPart::SetStatisticData(CharacterDBOperateInfo &proto)
{
	//杀怪数量
	CharacterDBOperateMutProto *protoKillMons =  proto.mutable_kill_mons();
	if (nullptr != protoKillMons)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapKillMonsNum.begin();
		for (; iter != m_statisticData.mapKillMonsNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoKillMons->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//杀怪数量（最后一刀）
	CharacterDBOperateMutProto *protoLastKillMons = proto.mutable_last_kill_mons();
	if (nullptr != protoLastKillMons)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapLastKillMonsNum.begin();
		for (; iter != m_statisticData.mapLastKillMonsNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoLastKillMons->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//参加活动次数
	CharacterDBOperateMutProto *protoAttendAct = proto.mutable_attend_act();
	if (nullptr != protoAttendAct)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapAttendActNum.begin();
		for (; iter != m_statisticData.mapAttendActNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoAttendAct->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//上一次参加活动时间
	CharacterDBOperateMutProto *protoLastAttendAct = proto.mutable_last_attend_act();
	if (nullptr != protoLastAttendAct)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapLastAttendAct.begin();
		for (; iter != m_statisticData.mapLastAttendAct.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoLastAttendAct->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//完成活动次数
	CharacterDBOperateMutProto *protoFinishAct = proto.mutable_finish_act();
	if (nullptr != protoFinishAct)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapFinishActNum.begin();
		for (; iter != m_statisticData.mapFinishActNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoFinishAct->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//通关副本次数
	CharacterDBOperateMutProto *protoPassDup = proto.mutable_pass_dup();
	if (nullptr != protoPassDup)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapPassDupNum.begin();
		for (; iter != m_statisticData.mapPassDupNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoPassDup->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//收集副业行为次数
	CharacterDBOperateMutProto *protoCollAction = proto.mutable_coll_action();
	if (nullptr != protoCollAction)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapCollDeputyNum.begin();
		for (; iter != m_statisticData.mapCollDeputyNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoCollAction->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//制造副业行为次数
	CharacterDBOperateMutProto *protoMakeAction = proto.mutable_make_action();
	if (nullptr != protoMakeAction)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapMakeDeputyNum.begin();
		for (; iter != m_statisticData.mapMakeDeputyNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoMakeAction->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//采集次数
	CharacterDBOperateMutProto *protoCollect= proto.mutable_collect();
	if (nullptr != protoCollect)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapCollectNum.begin();
		for (; iter != m_statisticData.mapCollectNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoCollect->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//制造次数
	CharacterDBOperateMutProto *protoMake = proto.mutable_make();
	if (nullptr != protoMake)
	{
		MAP_UINT32_UINT64::iterator iter = m_statisticData.mapMakeNum.begin();
		for (; iter != m_statisticData.mapMakeNum.end(); ++iter)
		{
			CharacterDBOperateProto *protoSingle = protoMake->add_operate_lst();
			if (nullptr != protoSingle)
			{
				protoSingle->set_id(iter->first);
				protoSingle->set_num(iter->second);
			}
		}
	}
	//
	proto.set_make_gold_quip(m_statisticData.nMakeGoldEquipNum);
	proto.set_identify(m_statisticData.nIdentifyNum);
	proto.set_arena_success(m_statisticData.nArenaSuccessNum);
	proto.set_die(m_statisticData.nDieNum);
	proto.set_kill_enemy(m_statisticData.nKillEnemyNum);
	proto.set_kill_enemy_camp(m_statisticData.nKillOtherCampNum);
	proto.set_charge(m_statisticData.nChargeNum);
	proto.set_gold(m_statisticData.nGoldNum);
	proto.set_treasure(m_statisticData.nTreasureNum);
	proto.set_pandos_trans(m_statisticData.nPandosTransNum);
	proto.set_world_chat(m_statisticData.nWorldChatNum);
	proto.set_refine_success(m_statisticData.nRefineSuccessNum);
	proto.set_refine_fail(m_statisticData.nRefineFailNum);
}


bool OperateLimitPart::AddOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t value)
{
	OperateLimit* pOperateLimit;
	if ((pOperateLimit = Mut(type)) == nullptr)
	{
		return false;
	}

	if (pOperateLimit->AddLimitCount(type, value) != 0)
	{
		return false;
	}

	return true;
}

bool OperateLimitPart::SetOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type, uint32_t value)
{
	OperateLimit* pOperateLimit;
	if ((pOperateLimit = Mut(type)) == nullptr)
	{
		return false;
	}

	uint32_t nNowTime = Time::Now().UnixSec();
	pOperateLimit->SetLimitCount(value);
	pOperateLimit->SetLastTime(nNowTime);

	return true;
}

OperateLimit* OperateLimitPart::Mut(PLAYER_ROLE_STATIS_TYPE_E type)
{
	uint32_t size = m_mOperateLimit.size();
	if ((uint32_t)type >= size)
	{
		return nullptr;
	}

	return &m_mOperateLimit[type];
}

int32_t OperateLimitPart::GetOprateLimit(PLAYER_ROLE_STATIS_TYPE_E type)
{
	OperateLimit* pOperateLimit;
	if ((pOperateLimit = Mut(type)) == nullptr)
	{
		return -1;
	}

	return pOperateLimit->GetLimitCount();
}

bool OperateLimitPart::DailyUpdate(uint64_t unixSec)
{
	uint32_t nNowTime = Time::Now().UnixSec();
	for (uint32_t i = 0; i < m_mOperateLimit.size(); i++)
	{
		if (m_mOperateLimit[i].GetUpdateType() == PRSUTE_DAY_UPDATE)
		{
			if (m_mOperateLimit[i].IsNeedUpdate(nNowTime))
			{
				m_mOperateLimit[i].SetLimitCount(0);
				m_mOperateLimit[i].SetLastTime(nNowTime);
			}
		}
	}
	return true;
}

bool OperateLimitPart::WeekUpdate(uint64_t unixSec)
{
	uint32_t nNowTime = Time::Now().UnixSec();
	for (uint32_t i = 0; i < m_mOperateLimit.size(); i++)
	{
		if (m_mOperateLimit[i].GetUpdateType() == PRSUTE_WEEK_UPDATE)
		{
			if (m_mOperateLimit[i].IsNeedUpdate(nNowTime))
			{
				m_mOperateLimit[i].SetLimitCount(0);
				m_mOperateLimit[i].SetLastTime(nNowTime);
			}
		}
	}
	return true;
}

//获取统计数据 acceptType:接取条件类型 cond1:条件参数1,cond2:条件参数2
uint64_t OperateLimitPart::GetStatisticData(int32_t acceptType, uint32_t cond1 /*= 0*/)
{
	/*
	M_ACCEPT_TYPE_TOTAL_KILL_MONS = 201,		//累计击杀指定怪物数量			201=怪物id=数量=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_LAST_ATTACK = 202,		//累计击杀指定怪物数量(最后一击)	202=怪物id=数量=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_JOIN_ACT = 211,			//累计参加指定活动次数			211=活动id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_FINISH_ACT = 212,		//累计完成指定活动次数			212=活动id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PASS_DUP = 221,			//累计通关指定副本次数			221=副本id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT = 231,	//累计收集副业行为				231=采集类型=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE = 232,		//累计制造副业行为				231=制造类型=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_COLLECT = 233,			//累计采集成功次数				232=采集id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_MAKE = 234,				//累计制造次数					233=制造id=次数=0=0=0=0

	M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP = 235,	//累计打造金色装备				234=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_IDENTIFY = 236,			//累计鉴定次数					235=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS = 241,		//累计竞技场胜利次数			241=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PLAYER_DIE = 251,		//累计玩家死亡次数				251=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_ONLINE = 252,			//累计在线时长					252=0=时长(分钟)=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_KILL_ENEMY = 261,		//累计杀死仇人					261=0=人数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP = 262,	//累计杀死敌对阵营玩家			262=0=人数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_CHARGE	= 271,			//累计充值指定金额				271=0=金额=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_GAIN_GOLD = 281,		//累计获得金币数量				281=0=金额=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_TREASURE =	291,		//累计挖宝次数					291=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS = 292,		//累计星盘传送次数				292=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_WORLD_CHAT = 293,		//累计世界聊天次数				293=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS = 294,	//累计精炼成功次数				294=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_REFINE_FAIL = 295,		//累计精炼失败次数				295=0=次数=0=0=0=0
	*/

	if (!g_GetOperateCfgMgr()->IsStatisticType(acceptType))
	{
		return 0;
	}
	uint64_t resultCount = 0;
	uint32_t param1 = cond1;
	const MAP_UINT32_UINT64 *pTotalMap = nullptr;
	if (M_ACCEPT_TYPE_TOTAL_KILL_MONS == acceptType)
	{
		pTotalMap = &m_statisticData.mapKillMonsNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_LAST_ATTACK == acceptType)
	{
		pTotalMap = &m_statisticData.mapLastKillMonsNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_JOIN_ACT == acceptType)
	{
		pTotalMap = &m_statisticData.mapAttendActNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_FINISH_ACT == acceptType)
	{
		pTotalMap = &m_statisticData.mapFinishActNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PASS_DUP == acceptType)
	{
		pTotalMap = &m_statisticData.mapPassDupNum;
	}
	/*else if (M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT == acceptType)
	{
		pTotalMap = &m_statisticData.mapCollDeputyNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE == acceptType)
	{
		pTotalMap = &m_statisticData.mapMakeDeputyNum;
	}*/
	else if (M_ACCEPT_TYPE_TOTAL_COLLECT == acceptType)
	{
		pTotalMap = &m_statisticData.mapCollectNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_MAKE == acceptType)
	{
		pTotalMap = &m_statisticData.mapMakeNum;
	}
	//单项统计数据
	else if (M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP == acceptType)
	{
		resultCount = m_statisticData.nMakeGoldEquipNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_IDENTIFY == acceptType)
	{
		resultCount = m_statisticData.nIdentifyNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS == acceptType)
	{
		resultCount = m_statisticData.nArenaSuccessNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PLAYER_DIE == acceptType)
	{
		resultCount = m_statisticData.nDieNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_KILL_ENEMY == acceptType)
	{
		resultCount = m_statisticData.nKillEnemyNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP == acceptType)
	{
		resultCount = m_statisticData.nKillOtherCampNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_CHARGE == acceptType)
	{
		resultCount = m_statisticData.nChargeNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_GAIN_GOLD == acceptType)
	{
		resultCount = m_statisticData.nGoldNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_TREASURE == acceptType)
	{
		resultCount = m_statisticData.nTreasureNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS == acceptType)
	{
		resultCount = m_statisticData.nPandosTransNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_WORLD_CHAT == acceptType)
	{
		resultCount = m_statisticData.nWorldChatNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS == acceptType)
	{
		resultCount = m_statisticData.nRefineSuccessNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_REFINE_FAIL == acceptType)
	{
		resultCount = m_statisticData.nRefineFailNum;
	}

	if (nullptr != pTotalMap)
	{
		MAP_UINT32_UINT64::const_iterator iter = pTotalMap->find(param1);
		resultCount = (iter != pTotalMap->end()) ? iter->second : 0;
	}
	
	return resultCount;
}

//更新统计数据
void OperateLimitPart::UpdateStatisticData(int32_t acceptType, uint32_t cond1 /*= 0*/, uint64_t cond2/* = 0*/)
{
	if (!g_GetOperateCfgMgr()->IsStatisticData(acceptType,cond1))
	{
		return;
	}
	/*
	M_ACCEPT_TYPE_TOTAL_KILL_MONS = 201,		//累计击杀指定怪物数量			201=怪物id=数量=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_LAST_ATTACK = 202,		//累计击杀指定怪物数量(最后一击)	202=怪物id=数量=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_JOIN_ACT = 211,			//累计参加指定活动次数			211=活动id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_FINISH_ACT = 212,		//累计完成指定活动次数			212=活动id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PASS_DUP = 221,			//累计通关指定副本次数			221=副本id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT = 231,	//累计收集副业行为				231=采集类型=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE = 232,		//累计制造副业行为				231=制造类型=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_COLLECT = 233,			//累计采集成功次数				232=采集id=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_MAKE = 234,				//累计制造次数					233=制造id=次数=0=0=0=0

	M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP = 235,	//累计打造金色装备				234=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_IDENTIFY = 236,			//累计鉴定次数					235=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS = 241,		//累计竞技场胜利次数			241=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PLAYER_DIE = 251,		//累计玩家死亡次数				251=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_ONLINE = 252,			//累计在线时长					252=0=时长(分钟)=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_KILL_ENEMY = 261,		//累计杀死仇人					261=0=人数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP = 262,	//累计杀死敌对阵营玩家			262=0=人数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_CHARGE	= 271,			//累计充值指定金额				271=0=金额=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_GAIN_GOLD = 281,		//累计获得金币数量				281=0=金额=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_TREASURE =	291,		//累计挖宝次数					291=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS = 292,		//累计星盘传送次数				292=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_WORLD_CHAT = 293,		//累计世界聊天次数				293=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS = 294,	//累计精炼成功次数				294=0=次数=0=0=0=0
	M_ACCEPT_TYPE_TOTAL_REFINE_FAIL = 295,		//累计精炼失败次数				295=0=次数=0=0=0=0
	*/
	uint32_t param1 = cond1;
	uint32_t param2 = cond2;
	MAP_UINT32_UINT64 *pTotalMap = nullptr;
	if (M_ACCEPT_TYPE_TOTAL_KILL_MONS == acceptType)
	{
		pTotalMap = &m_statisticData.mapKillMonsNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_LAST_ATTACK == acceptType)
	{
		pTotalMap = &m_statisticData.mapLastKillMonsNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_JOIN_ACT == acceptType)
	{
		//参加活动需要验证下，上次参加活动的事件是否和这次在同一次活动中
		MAP_UINT32_UINT64::iterator iterAct = m_statisticData.mapLastAttendAct.find(param1);
		if (iterAct != m_statisticData.mapLastAttendAct.end())
		{
			if (!g_GetGActivityMgr()->IsDuringAct(param1,iterAct->second))
			{
				//不再活动期间
				return;
			}
			iterAct->second = g_GetGlobalServerTime()->UnixSec();
		}
		else
		{
			m_statisticData.mapLastAttendAct[param1] = g_GetGlobalServerTime()->UnixSec();
		}

		pTotalMap = &m_statisticData.mapAttendActNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_FINISH_ACT == acceptType)
	{
		pTotalMap = &m_statisticData.mapFinishActNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PASS_DUP == acceptType)
	{
		pTotalMap = &m_statisticData.mapPassDupNum;
	}
	/*else if (M_ACCEPT_TYPE_TOTAL_DEPUTY_COLLECT == acceptType)
	{
		pTotalMap = &m_statisticData.mapCollDeputyNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_DEPUTY_MAKE == acceptType)
	{
		pTotalMap = &m_statisticData.mapMakeDeputyNum;
	}*/
	else if (M_ACCEPT_TYPE_TOTAL_COLLECT == acceptType)
	{
		pTotalMap = &m_statisticData.mapCollectNum;
	}
	else if (M_ACCEPT_TYPE_TOTAL_MAKE == acceptType)
	{
		pTotalMap = &m_statisticData.mapMakeNum;
	}
	//单项统计数据
	else if (M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP == acceptType)
	{
		m_statisticData.nMakeGoldEquipNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_IDENTIFY == acceptType)
	{
		m_statisticData.nIdentifyNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS == acceptType)
	{
		m_statisticData.nArenaSuccessNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PLAYER_DIE == acceptType)
	{
		m_statisticData.nDieNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_KILL_ENEMY == acceptType)
	{
		m_statisticData.nKillEnemyNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP == acceptType)
	{
		m_statisticData.nKillOtherCampNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_CHARGE == acceptType)
	{
		m_statisticData.nChargeNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_GAIN_GOLD == acceptType)
	{
		m_statisticData.nGoldNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_TREASURE == acceptType)
	{
		m_statisticData.nTreasureNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS == acceptType)
	{
		m_statisticData.nPandosTransNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_WORLD_CHAT == acceptType)
	{
		m_statisticData.nWorldChatNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS == acceptType)
	{
		m_statisticData.nRefineSuccessNum += param2;
	}
	else if (M_ACCEPT_TYPE_TOTAL_REFINE_FAIL == acceptType)
	{
		m_statisticData.nRefineFailNum += param2;
	}

	if (nullptr != pTotalMap)
	{
		MAP_UINT32_UINT64::iterator iter = pTotalMap->find(param1);
		if (iter != pTotalMap->end())
		{
			iter->second += param2;
		}
		else
		{
			pTotalMap->insert(make_pair(param1, param2));
		}
	}
}

////////////////////////////////// 事件处理接口 ////////////////////////////////////////
//共享杀怪记录
void OperateLimitPart::ShareKillMonsCount(uint32_t monsId,int32_t count)
{
	//击杀怪物计数
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_MONS, monsId, count);
}	//击杀敌对阵营的玩家
void OperateLimitPart::KillEnemyCampPlayer()
{
	//击杀怪物计数
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_OTHER_CAMP, 0, 1);
}
//属性改变
void OperateLimitPart::OnAttrChange(uint32_t PANum,int64_t nChangeValue)
{
	if (P_GOLD == PANum && nChangeValue > 0)
	{
		//累计获得金币
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_GAIN_GOLD, 0, nChangeValue);
	}
}
//怪物死亡
void OperateLimitPart::OnMonsDieEvent(DieEvent &dieEvent)
{
	if (dieEvent.killerCid != m_pMaster->GetCid())
	{
		return;
	}
	CharIDType selfCid = m_pMaster->GetCid();
	//击杀怪物（最后一刀）
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_LAST_ATTACK, dieEvent.monsterId, dieEvent.count);
	//击杀怪物计数
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_MONS, dieEvent.monsterId, dieEvent.count);
	//
	Scene *pScene = m_pMaster->GetScene();
	if (nullptr == pScene)
	{
		return;
	}
	Monster *pMonster = pScene->GetMonster(dieEvent.nCid);
	if (nullptr == pMonster)
	{
		return;
	}
	//Point3<float> pos = pMonster->GetPos();
	//统计仇恨列表和归属列表中组队的玩家，可能会有重复部分
	SET_UINT64 setTarget;
	setTarget.clear();
	//
	VEC_UINT64::iterator iterHate = dieEvent.hateTargetList.begin();
	for (; iterHate != dieEvent.hateTargetList.end(); ++iterHate)
	{
		setTarget.insert((*iterHate));
	}
	ORDER_MAP_UINT32_VEC_UINT64::iterator iterTeam = dieEvent.mapTargetTeamMem.begin();
	for (; iterTeam != dieEvent.mapTargetTeamMem.end(); ++iterTeam)
	{
		VEC_UINT64 &vecMem = iterTeam->second;
		VEC_UINT64::iterator iterMem = vecMem.begin();
		for (; iterMem != vecMem.end(); ++iterMem)
		{
			setTarget.insert((*iterMem));
		}
	}
	//任务杀怪计数
	SET_UINT64::iterator iterTarget = setTarget.begin();
	for (; iterTarget != setTarget.end(); ++iterTarget)
	{
		CharIDType shareCid = (*iterTarget);
		if (selfCid == shareCid)
		{
			continue;
		}
		Player* pPlayer = g_GetCreatureMgr()->GetPlayer(shareCid);
		if (nullptr != pPlayer)
		{
			OperateLimitPart *pOperateLimitPart = dynamic_cast<OperateLimitPart*>(pPlayer->GetPart(PART_ADVENTURE));
			if (nullptr != pOperateLimitPart)
			{
				pOperateLimitPart->ShareKillMonsCount(dieEvent.monsterId, dieEvent.count);
			}
		}
	}
}
//玩家死亡
void OperateLimitPart::OnPlayerDieEvent(DieEvent &dieEvent)
{
	//玩家死亡次数
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_PLAYER_DIE,0, 1);
	//判断击杀着是否是敌对阵营
	Player *pKillerPlayer = g_GetCreatureMgr()->GetPlayer(dieEvent.killerCid);
	if (nullptr != pKillerPlayer && pKillerPlayer->GetAttr(C_CAMP_ID) != m_pMaster->GetAttr(C_CAMP_ID))
	{
		OperateLimitPart *pKillOperateLimitPart = dynamic_cast<OperateLimitPart*>(pKillerPlayer->GetPart(PART_OPERATELIMIT));
		if (nullptr != pKillOperateLimitPart)
		{
			pKillOperateLimitPart->KillEnemyCampPlayer();
		}		
	}	
}
//通关副本
void OperateLimitPart::OnPassEvent(PassDupEvent &passEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_PASS_DUP, passEvent.dupId, 1);
}

//收集成功
void OperateLimitPart::OnCollectEvent(CollectOperateEvent &collSucessEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_COLLECT, collSucessEvent.type, 1);
}
//制造成功
void OperateLimitPart::OnMakeEvent(ForgeEquipEvent &makeEvent)
{
	//制造
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE, makeEvent.type, 1);
	//打造金色装备
	if (EQuality_gold == makeEvent.quality)
	{
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE_GOLD_EQUIP, makeEvent.itemID, 1);
	}
}
//制造道具
void OperateLimitPart::OnMakeItemEvent(MakeOperateEvent &operateEvent)
{
	//制造
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_MAKE, operateEvent.type, 1);
}
//竞技场挑战结果
void OperateLimitPart::OnArenaResultEvent(ArenaResultEvent &resultEvent)
{
	if (resultEvent.isWin)
	{
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_AREAN_SUCESS, 0, 1);
	}
}
//充值
void OperateLimitPart::OnChargeEvent(PayEvent &payEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_CHARGE, 0, payEvent.money);
}
//挖宝
void OperateLimitPart::OnTreasureEvent(TreasureEvent &treasureEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_TREASURE, 0, 1);
}
//进入场景
void OperateLimitPart::OnEnterSceneEvent(EnterSceneEvent &enterEvent)
{
	//星盘传送次数
	if (ETransType_Pandos == enterEvent.transParam.transType)
	{
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_PANDOS_TRANS, 0, 1);
	}
}
//精炼
void OperateLimitPart::OnRefineEvent(EquipRefineEvent &refineEvent)
{
	if (refineEvent.result)
	{
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_REFINE_SUCESS, 0, 1);
	}
	else
	{
		UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_REFINE_FAIL, 0, 1);
	}
	
}

//鉴定
void OperateLimitPart::OnIdentifyEvent(EquipIdentifyEvent &identifyEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_IDENTIFY, 0, 1);
}

//参加活动
void OperateLimitPart::OnAttendActEvent(AttendActEvent &attendEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_JOIN_ACT, attendEvent.activityId, 1);
}
//完成活动
void OperateLimitPart::OnFinishActEvent(FinishActEvent &finishEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_FINISH_ACT, finishEvent.activityId, 1);
}
//世界聊天
void OperateLimitPart::OnWorldChatEvent(ChatWorldEvent &chatEvent)
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_WORLD_CHAT, 0, 1);
}
//击杀仇人
void OperateLimitPart::OnKillEnemyEvent()
{
	UpdateStatisticData(M_ACCEPT_TYPE_TOTAL_KILL_ENEMY, 0, 1);
}